function [data]=correct_line_shift(data,template)
% estimates and corrects the shift between successive scan lines

if nargin<2
    template=mean(data,3);
end


twoddata=0;
if size(data,3)==1
    tdata(:,:,1)=data;
    tdata(:,:,2)=data;
    twoddata=1;
    data=tdata;
end

shift=estimate_line_shift(template);
%disp(['Estimated shift is ' num2str(shift)]);

if shift~=0
    for ind=1:size(data,1)
        if rem(ind,2)==1
            data(ind,:,:)=circshift(squeeze(data(ind,:,:)),[shift 0]);
        end
    end
end

if twoddata
    data=data(:,:,1);
end

%figure;imagesc(mean(data,3))
